package com.chat.security.authentication;

import com.chat.security.entity.JWTLoginUser;
import com.chat.security.service.JwtTokenService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;


public class TokenAuthentication implements Authentication {

    private JwtTokenService tokenService;

    private String token;
    private JWTLoginUser loginUser;
    private boolean authenticated;

    public TokenAuthentication(String token,JwtTokenService tokenService) {

        this.token = token;
        this.tokenService = tokenService;
    }

    public JwtTokenService getTokenService() {
        return tokenService;
    }

    public String getToken() {
        return token;
    }

    public void setLoginUser(JWTLoginUser loginUser) {
        this.loginUser = loginUser;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getDetails() {
        return token;
    }

    @Override
    public Object getPrincipal() {
        return loginUser;
    }

    @Override
    public boolean isAuthenticated() {
        return authenticated;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        this.authenticated = isAuthenticated;
    }

    @Override
    public String getName() {
        return loginUser.getUserName();
    }
}
